package com.oyjd.framework.ui.condsel;

import android.content.Context;
import android.view.MotionEvent;
import android.widget.ImageView;

/**
 * 滑动选择条件控件指针
 * 
 * @author 欧建东
 * @email oyjd@163.com
 * 
 */
public class CondMask extends ImageView {
	public static final int STATUS_STOP = 1;
	public static final int STATUS_MOVE = 2;
	/**
	 * 当前状态
	 */
	protected int status = STATUS_STOP;

	/**
	 * 当前指针位置
	 */
	protected int pos = 0;

	/**
	 * 当前参照指针
	 */
	protected CondMask mask;

	/**
	 * 构造函数
	 * 
	 * @param context
	 */
	public CondMask(Context context) {
		super(context);
	}

	/**
	 * 设置参照对象
	 * 
	 * @param mask
	 */
	protected void setLook(CondMask mask) {
		this.mask = mask;
	}

	/**
	 * 移动指针
	 * 
	 * @param x
	 */
	protected void moveMask(int x) {
		if (STATUS_MOVE == status) {
			moveMaskDirect(x);
		}
	}

	/**
	 * 直接移动指针
	 * 
	 * @param x
	 */
	protected void moveMaskDirect(int x) {
		setFrame(x, this.getTop(), x + this.getWidth(), this.getBottom());
	}

	/**
	 * 手势事件
	 */
	public boolean onTouchEvent(MotionEvent event) {
		if (null == mask || STATUS_MOVE != mask.status) {
			status = STATUS_MOVE;
		}
		return super.onTouchEvent(event);
	}
}
